{include file="public/header"}
<body class="work_body">
<div class="bg_fixed"></div>
<div class="work_section1" style="background: none">
    <a href="{:url('User/work_submit')}">
        <img src="__PUBLIC__/home/images/a2_1.png" alt="" class="a1">
    </a>
    <p class="p1">工单提交</p>
</div>
<div class="work_section4">
    <div class="container">
        <form action="">
            <div class="f1">
                <p class="p1">联系信息<span class="s1">*</span></p>
                <div class="inline">
                    <input type="text" placeholder="请输入" name="link_info">
                </div>
            </div>
            <div class="f1">
                <p class="p1">工单标题<span class="s1">*</span></p>
                <div class="inline">
                    <input type="text" placeholder="请输入" name="title1">
                </div>
            </div>
            <div class="f1">
                <p class="p1">上传截图<span class="s1">*</span></p>
                <div class="list">
                    <div class="st_all"></div>
                    <img src="__PUBLIC__/home/images/plus.png" alt="" class="img_change">
                    <input type="file" id="file" onchange="imgChange(this);" style="height: 0px;width: 0px;" />
                </div>
            </div>
            <div class="f1">
                <p class="p1">简单描述</p>
                <div class="inline" style="background: rgba(255,255,255,0.2);">
                    <textarea name="desc" id=""  placeholder="请输入"></textarea>
                </div>
            </div>
            <div class="f2">
                <input type="hidden" name="img_url" id="upload_geturl">
                <input type="hidden" name="type" value="{$type}">
                <input type="button" value="提交" onclick="tj()">
            </div>
        </form>
    </div>
</div>

</body>
<script type="text/javascript">
    var is_app=0;
    try {
        is_app = android.getType();
    }catch (e) {
    }
    $(function () {
        $(".img_change").click(function(){
            if(is_app==1){
                android.uploadImage(location.origin+"/home/Upload/appupimg.html");
            }else{
                $(this).siblings("input").click();
            }
        })
    })

    function tj() {
        var form_data = $("form").serialize();
        $.ajax({
            url:"{:url('addSheet')}",
            data:form_data,
            dataType:"json",
            type:"post",
            success:function (res) {
                layer.msg(res.result_info);
                if(res.result_code == 0){
                    setTimeout(function () {
                        location.href="{:url('User/index')}"
                    },666)
                }
            }
        });

    }

    //安卓回调
    function setImage(img_url) {
        $(".img_change").attr('src',img_url); // 修改img标签src属性值
        $("#upload_geturl").val(img_url);
    }
    function imgChange(obj) {
        var docObj=$(obj).get(0);
        if (docObj.files && docObj.files[0]) {
            if(!/image\/\w+/.test(docObj.files[0].type)){
                //图片文件的type值为image/png或image/jpg
                layer.msg("文件必须为图片！");
                return false;
            }
            var formData = new FormData();
            formData.append("files",docObj.files[0]);
            $.ajax({
                url: "{:url('Upload/upimg')}",
                type: "POST",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType: false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData: false,
                success: function (rs) {
                    rs = JSON.parse(rs);
                    if(rs.status==0){
                        setImage(rs.data)
                    }else{
                        layer.alert(rs.info,{shade:0.2});return false;
                    }
                },
                error: function () {
                    layer.msg('系统错误，请稍后重试');
                }
            });
        } else {
            layer.msg('请上传图片');
        }
        return true;
    }
</script>
